const { query } = require('../utils/db')
// const crypto = require('../utils/crypto')
module.exports = {
  // 注册用户(Y)
  async createUser(userInfo) {
    let { username, wx_openid, head_url, sex, account, psw, city, province } = userInfo
    if (!wx_openid) {
      return { suc: false }
    }
    username = crypto.toBase64(username)
    let sql = 'call sp_create_user(?,?,?,?,?,?,?,?)'
    let rows = await query(sql, [username, wx_openid, head_url, sex, account, psw, city, province])
    if (rows[0].length == 1) {
      return { suc: true, data: rows[0][0] }
    }
    return { suc: false }
  },
  // 用户登录(Y)
  async login(tel, code) {
    let sql = ``
    let rows = await query(sql, [tel, code])
    let res = rows[0]
    if (!res || res.length == 0) {
      return { suc: false }
    }
    return { suc: true, data: res[0] }
  }
}
